apiVersion: batch/v1
kind: Job
metadata:
  name: alerting-db-init-job
  namespace: kubesphere-alerting-system
  labels:
    app: alerting
    job: alerting-db-init
    version: v0.1.0
spec:
  backoffLimit: 6
  completions: 1
  parallelism: 1
  template:
    metadata:
      labels:
        app: alerting
        job: alerting-db-init
        version: v0.1.0
      name: alerting-db-init
    spec:
      initContainers:
      - name: wait-mysql
        image: {{ busybox_repo }}:{{ busybox_tag }}
        imagePullPolicy: IfNotPresent
        command: ['sh', '-c', 'until nc -z {{ dbHost }} {{ dbPort }}; do echo "waiting for mysql"; sleep 2; done;']
      containers:
      - command: ["/flyway/sql/ddl/ddl_init.sh", "-h{{ dbHost }}", "-uroot", "--connect-timeout=5"]
        env:
        - name: PASSWORD
          value: "password"
        image: {{ alerting_dbinit_repo }}:{{ alerting_dbinit_tag }}
        imagePullPolicy: {{ ks_image_pull_policy }}
        name: alerting-db-init
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: OnFailure
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
